home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / MERGE2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.2 KB  |  42 lines

  1. /* merge2.c - generalized external sort */
  2. #include   "stdio.h"
  3. #include   "cminor.h"
  4. #include   "merge1.h"
  5. #include   "sortspec.h"
  6.  
  7.  
  8. int  (*compfun)  () ;        /* store address of compare fun. here */
  9. extern    SORTSPEC sspec ;    /* sortspec. filled out by getspec */
  10.  
  11. char scra[68] = "scra" ;        /* prefixes for scratch file names */
  12. char scrb[68] = "scrb" ;
  13.  
  14. main(argc,argv)
  15.   int    argc ;            /* number of words in command line */
  16.   char *argv[] ;        /* pointers to each word */
  17.   {
  18.      /* check to see that file names were specified */
  19.      if( argc < 3 )
  20.     {  printf(" need file names \n") ;
  21.        printf(" USAGE:  merge1   input-file   output-file \n") ;
  22.        exit(1) ;
  23.     }
  24.      getspec(argc,argv) ;    /* get sort spec. from the command line */
  25.      compfun = sspec.pcomp ;    /* set up compare fun. address */
  26.      dosort(argv[1],argv[2]) ;    /* do the sort */
  27.   }
  28.  
  29.  
  30. int  dosort(fromfile,tofile)
  31.   char    fromfile[] ;        /* input for sort */
  32.   char    tofile[] ;        /* put the output here */
  33.   {
  34.      int   nruns ;
  35.                 /* form runs from input file */
  36.      nruns = formruns(fromfile,scra,tofile) ;
  37.                 /* now merge runs */
  38.      domerge(scra,scrb,tofile,nruns) ;
  39.   }
  40.  
  41.  
  42.